from typing import List, Optional
from datetime import datetime
from pydantic import BaseModel, Field
from app.core.enums import QuestionType, Difficulty, QuestionStatus
from enum import Enum

class QuestionStatus(str, Enum):
    DRAFT = "draft"           # 草稿
    PENDING = "pending"       # 待审核
    APPROVED = "approved"     # 已通过
    REJECTED = "rejected"     # 已拒绝
    ARCHIVED = "archived"     # 已归档

class QuestionBase(BaseModel):
    title: str = Field(..., min_length=1, max_length=500)
    type: str = Field(..., min_length=1, max_length=32)
    options: Optional[str] = Field(None, max_length=1000)
    answer: str
    tags: Optional[str] = Field(None, max_length=500)
    difficulty: str = Field(..., min_length=1, max_length=16)
    topic: str = Field(..., max_length=100)
    reference_links: Optional[str] = Field(None, max_length=500)
    explanation: Optional[str] = Field(None, max_length=1000)
    status: Optional[str] = Field(None, max_length=10)

class QuestionCreate(QuestionBase):
    pass

class QuestionUpdate(BaseModel):
    title: Optional[str] = Field(None, min_length=1, max_length=500)
    type: Optional[str] = Field(None, min_length=1, max_length=32)
    options: Optional[str] = Field(None, max_length=1000)
    answer: Optional[str] = None
    tags: Optional[str] = Field(None, max_length=500)
    difficulty: Optional[str] = Field(None, min_length=1, max_length=16)
    topic: Optional[str] = Field(None, max_length=100)
    reference_links: Optional[str] = Field(None, max_length=500)
    explanation: Optional[str] = Field(None, max_length=1000)
    status: Optional[str] = Field(None, max_length=10)

class QuestionInDB(QuestionBase):
    id: int
    created_at: datetime
    updated_at: datetime

    class Config:
        from_attributes = True

class QuestionFilter(BaseModel):
    type: Optional[str] = None
    difficulty: Optional[str] = None
    topic: Optional[str] = None
    status: Optional[str] = None
    tags: Optional[str] = None
    search: Optional[str] = None
    page: int = 1
    page_size: int = 10

class QuestionList(BaseModel):
    total: int
    items: List[QuestionInDB]

class QuestionImportResult(BaseModel):
    total_processed: int
    successfully_imported: int
    message: str 